import request from '@/utils/request';

export async function _search(data?: any) {
  return request(`/AllLinks/geo/object/_search`, {
    method: 'POST',
    data,
  });
}

export async function _search_page(data?: any) {
  return request(`/AllLinks/geo/object/_search/_page`, {
    method: 'POST',
    data,
  });
}

export async function _search_geo_json(data?: any) {
  console.log('localStorage.getItem', localStorage.getItem('user-detail'))
    const user = JSON.parse(localStorage.getItem('user-detail') || '{}')
    if(user.tenants && user.tenants[0]){
      if(data.filter.where == 'objectType not device'){
        return request(`/AllLinks/geo/object/_search/tenant/geo.json`, {
          method: 'POST',
          data,
        });
      }else{
        return request(`/AllLinks/geo/object/_search/geo.json`, {
          method: 'POST',
          data,
        });
      }
    }else{
      return request(`/AllLinks/geo/object/_search/geo.json`, {
        method: 'POST',
        data,
      });
    }
}

export async function saveByGeoJson(data?: any) {
  return request(`/AllLinks/geo/object/geo.json`, {
    method: 'POST',
    data,
  });
}

export async function _delete(id: any) {
  return request(`/AllLinks/geo/object/${id}`, {
    method: 'DELETE',
  });
}

